package com.nulldev.util.web.HttpServer3.extensions.websocket.peers;

import java.util.Collection;
import java.util.Map;
import java.util.UUID;

import com.nulldev.util.data.Arrays.maps.trie.TrieMap;
import com.nulldev.util.web.HttpServer3.extensions.websocket.Peer;

public class PeerManager {

	private final Map<UUID, Peer> peers = new TrieMap<UUID, Peer>();

	public PeerManager() {
	}

	public boolean peerExists(final UUID uuid) {
		return this.peers.containsKey(uuid);
	}

	public Peer peer(final UUID uuid) {
		return this.peers.get(uuid);
	}

	public void registerPeer(final Peer peer) {
		this.peers.put(peer.getUUID(), peer);
	}

	public void removePeer(Peer peer) {
		this.peers.remove(peer.getUUID());
	}

	public Collection<Peer> clients() {
		return this.peers.values();
	}
}
